package com.hejia.bulbul.scheduler;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;

import com.hejia.alauda.entity.WarningSetting;
import com.hejia.alauda.service.ConfigureService;

/**
 * 订单失败检查预警作业
 * 每15分钟巡检一次
 * @author hyr
 *
 */
public class OrderCheckWarningScheduler {

	private static final Log Logger = LogFactory.getLog(OrderCheckWarningScheduler.class);
	
	@Resource
	private ConfigureService warningService;
	
	// [秒] [分] [小时] [日] [月] [周] [年]
	@Scheduled(cron = "0 0/15 * * * ?")
	@Async("executor")
	public void check(){
		
		Logger.debug("开始订单失败检查预警作业");
		
		WarningSetting warningSetting = this.warningService.getWarningSetting();
		if(warningSetting == null || !warningSetting.getOrderSwitch()){
			return;
		}
		
		warningService.checkFailOrders();
		
		Logger.debug("结束订单失败检查预警作业");
	}
}
